
import base64
import hashlib
from typing import Union
__all__=["b64encode","b64decode"]
def b64encode(context, decode: bool = True) -> Union[str, bytes]:
    if isinstance(context, bytes):
        encoded_bytes = base64.b64encode(context)
    else:
        encoded_bytes = base64.b64encode(_ensure_str(context).encode('utf-8'))

    return encoded_bytes.decode('utf-8') if decode else encoded_bytes


def b64decode(context: str, decode: bool = True) -> Union[str, bytes]:
    decoded_bytes = base64.b64decode(_ensure_str(context))

    return decoded_bytes.decode('utf-8') if decode else decoded_bytes
def get_md5(*args):
    """
    @summary: 获取唯一的32位md5
    ---------
    @param args: 参与联合去重的值
    ---------
    @result: 7c8684bcbdfcea6697650aa53d7b1405
    """
    m = hashlib.md5()
    for arg in args:
        m.update(str(arg).encode())

    return m.hexdigest()


def _ensure_str(text) -> str:
    if not text:
        return ""
    else:
        return str(text)

